package net.learn.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.learn.framework.common.page.PageResult;
import net.learn.framework.common.utils.Result;
import net.learn.system.query.SysRadioDetailQuery;
import net.learn.system.query.SysRadioQuery;
import net.learn.system.service.SysRadioDetailService;
import net.learn.system.vo.SysRadioDetailVO;
import net.learn.system.vo.SysRadioVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 李立志
 * @since 2022-04-02
 */
@RestController
@RequestMapping("sys/radiodetail")
@Tag(name="单选题详情")
@AllArgsConstructor
public class SysRadioDetailController {

    @Autowired
    SysRadioDetailService radioDetailService;

    @GetMapping("getRadioDetail")
    @Operation(summary = "分页获取单选题详情列表")
    public Result<PageResult<SysRadioDetailVO>> getRadioDetail(@Valid SysRadioDetailQuery query){
        PageResult<SysRadioDetailVO> page = radioDetailService.qryRadioDetailListPage(query);
        return Result.ok(page);
    }
    @GetMapping("getRadioDetailList")
    @Operation(summary = "获取单选题详情列表")
    public Result<List<SysRadioDetailVO>> getRadioDetailList(@RequestBody @Valid SysRadioDetailQuery query){
        List<SysRadioDetailVO> list = radioDetailService.getRadioDetailArray();

        return Result.ok(list);
    }
    @GetMapping("getPaperRadioList")
    @Operation(summary = "获取试卷题库")
    public Result<List<SysRadioDetailVO>> getPaperRadioList(@RequestBody @Valid SysRadioDetailQuery query){
        List<SysRadioDetailVO> list = radioDetailService.qryPaperRadioList(query);

        return Result.ok(list);
    }
    @GetMapping("getPaperRadioCondition")
    @Operation(summary = "获取试卷题库")
    public Result<List<SysRadioDetailVO>> getPaperRadioCondition(@RequestBody @Valid SysRadioDetailQuery query){
        List<SysRadioDetailVO> list = radioDetailService.qryPaperRadioCondition(query);

        return Result.ok(list);
    }
    @PutMapping
    @Operation(summary = "修改单选题详情")
    public Result<String> updateRadioDetail(@RequestBody @Valid SysRadioDetailVO vo){
        radioDetailService.updateRadioDetail(vo);

        return Result.ok();
    }
    @PostMapping("save")
    @Operation(summary = "新增单选题详情")
    public Result<String> save(@RequestBody List<SysRadioDetailVO> radioDetailList){
        for (SysRadioDetailVO vo : radioDetailList) {
            radioDetailService.addRadioDetail(vo);
        }
        return Result.ok();
    }
    @DeleteMapping
    @Operation(summary = "删除单选题详情")
    public Result<String> delete(@RequestBody List<Long> idList){
        radioDetailService.delete(idList);
        return Result.ok();
    }
}

